package com.surprise.redis;

/**
 * RedisKeyGenerator.java
 * @author nick
 * 2015年2月10日
 */
public class RedisKeyGenerator {
	/**
     * COMMON:ZSET:LIKE:USER:${type}:${uid}
     */
    private static final String COMMON_ZSET_LIKE_TEMPLATE = "COMMON:ZSET:LIKE:USER:%d:%d";

    /**
     * COMMON:ZSET:LIKE_COUNT:${type}
     */
    private static final String COMMON_ZSET_LIKE_COUNTER_TEMPLATE = "COMMON:ZSET:LIKE_COUNT:%d";

    /**
     * COMMON:ZSET:LIKE:MQ
     */
    private static final String COMMON_LIST_LIKE_MQ = "COMMON:LIST:LIKE:MQ";
    
    /**
     * COMMON:ZSET:STORE:USER:${type}:${uid}
     */
    private static final String COMMON_ZSET_STORE_TEMPLATE = "COMMON:ZSET:STORE:USER:%d:%d";

    /**
     * COMMON:LIST:STORE:MQ
     */
    private static final String COMMON_LIST_STORE_MQ = "COMMON:LIST:STORE:MQ";

    /**
     * COMMON:ZSET:STORE_COUNT:${type}
     */
    private static final String COMMON_ZSET_STORE_COUNTER_TEMPLATE = "COMMON:ZSET:STORE_COUNT:%d";
    
    /**
     * id计数器
     * COMMON:KV:IDGENERATOR:${type}
     * type例如评论
     */
    private final static String COMMON_KV_IDGENERATOR = "COMMON:KV:IDGENERATOR:%s";

    /**
     * 楼层计数器
     * COMMENT:HASH:LAYER
     */
    private final static String COMMENT_HASH_LAYER = "COMMENT:HASH:LAYER";
    
    /**
     * 用户session
     * USER:KV:SESSION:${sid}
     */
    private final static String USER_KV_SESSION = "USER:KV:SESSION:%s";
    
    /**
     * b端用户session
     * USER:KV:SESSION:${sid}
     */
    private final static String BUSER_KV_SESSION = "BUSER:KV:SESSION:%s";
    
    /**
     * 单个优惠总数
     */
    private final static String COMMON_KV_COUPON_CODE_TOTAL = "COMMON:KV:COUPON:CODE:TOTAL:%d";
    
    /**
     * 单个优惠已抢数
     */
    private final static String COMMON_KV_COUPON_CODE_COUNT = "COMMON:KV:COUPON:CODE:COUNT:%d";
    
    /**
     * 验证码
     * PHONE:KV_VERIFYCODE:${phone}
     */
    private final static String PHONE_KV_VERIFYCODE = "PHONE:KV_VERIFYCODE:%s";
    
    /**
     * 分享
     * SHARE:KV:${type}:${id}
     */
    private final static String SHARE_KV_COUNT = "SHARE:KV:%d:%d";
    
    public static String generateLikeZSetKey(int type, long uid) {
        return String.format(COMMON_ZSET_LIKE_TEMPLATE, type, uid);
    }

    public static String generateLikeCounterKey(int type) {
        return String.format(COMMON_ZSET_LIKE_COUNTER_TEMPLATE, type);
    }

    public static String generateLikeMQKey() {
        return COMMON_LIST_LIKE_MQ;
    }

    public static String generateStoreZSetKey(int type, long uid) {
        return String.format(COMMON_ZSET_STORE_TEMPLATE, type, uid);
    }

    public static String generateStoreMQKey() {
        return COMMON_LIST_STORE_MQ;
    }

    public static String generateStoreCounterKey(int type) {
        return String.format(COMMON_ZSET_STORE_COUNTER_TEMPLATE, type);
    }
    
    /**
     * id计数器
     * @param s
     * @return
     */
    public static String commonKvIdgenerator(String s) {
        return String.format(COMMON_KV_IDGENERATOR, s);
    }
    
    /**
     * 楼层计数器
     * @return
     */
    public static String commentHashLayer() {
    	return COMMENT_HASH_LAYER;
    }
    
    /**
     * 用户session
     * @param sid
     * @return
     */
    public static String userKvSession(String sid) {
    	return String.format(USER_KV_SESSION, sid);
    }
    
    /**
     * b端用户session
     * @param sid
     * @return
     */
    public static String buserKvSession(String sid) {
        return String.format(BUSER_KV_SESSION, sid);
    }
    
    /**
     * 手机号验证码器时效
     * @param phone
     * @return
     */
    public static String phoneKvVerifycode(String phone) {
    	return String.format(PHONE_KV_VERIFYCODE, phone);
    }
    
    /**
     * coupon可抢个数
     * @param id
     * @return
     */
    public static String generateCouponCodeTotalKey(long id) {
    	return String.format(COMMON_KV_COUPON_CODE_TOTAL, id);
    }
    
    /**
     * coupon已抢计数
     * @param id
     * @return
     */
    public static String generateCouponCodeCountKey(long id) {
    	return String.format(COMMON_KV_COUPON_CODE_COUNT, id);
    }
    
    /**
     * share计数
     * @param type
     * @param id
     * @return
     */
    public static String generateShareCountKey(int type, long id) {
        return String.format(SHARE_KV_COUNT, type, id);
    }
}
